package com.dhl.stategy.comparter;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author 10720
 */
public class Compare<T> {

    public void compare(T[] objs, Comparator<T> comparator) {
        // 选择排序算法
        int length = objs.length;
        for (int i = 0; i < length - 1; i++) {
            int maxIndex = i;
            for (int j = i + 1; j < length; j++) {
                if (comparator.compare(objs[maxIndex], objs[j]) < 0) {
                    maxIndex = j;
                }
            }
            swap(objs, i, maxIndex);
        }
    }


    /**
     *
     *
     * @param objs
     * @param i
     * @param j
     */
    private void swap(T[] objs, int i, int j) {
        T temp = objs[i];
        objs[i] = objs[j];
        objs[j] = temp;
    }

}
